//
//  OtherTypeViewController.m
//  LazyCat
//
//  Created by jike on 15/12/22.
//  Copyright (c) 2015年 zhanshu. All rights reserved.
//

#import "OtherTypeViewController.h"
#import "OtherTypeViewCell.h"
#import "AddTypeViewController.h"

@interface OtherTypeViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>
{
    UICollectionView *_collectionView;
}

@end

@implementation OtherTypeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initNav:@"商品分类" doBack:YES];
    
    UIView *lineV = [[UIView alloc]initWithFrame:CGRectMake(0, 63, ScreenWidth, 1)];
    lineV.backgroundColor = [UIColor lightGrayColor];
    lineV.alpha = 0.2;
    [self.view addSubview:lineV];
    
    [self createCollection];
    
    
    
    
}

-(void)createCollection
{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    [layout setScrollDirection:UICollectionViewScrollDirectionVertical];
    layout.itemSize = CGSizeMake(ScreenWidth/4,  ScreenWidth/4);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64,ScreenWidth, ScreenHeight-64) collectionViewLayout:layout];
    _collectionView.delegate = self;
    _collectionView.dataSource =self;
    _collectionView.backgroundColor = [UIColor whiteColor];
    _collectionView.alwaysBounceVertical = YES;
    [self.view addSubview:_collectionView];
    [_collectionView registerNib:[UINib nibWithNibName:@"OtherTypeViewCell" bundle:nil] forCellWithReuseIdentifier:@"Cell"];
 
    [_collectionView registerClass:[UICollectionReusableView class]  forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"Header"];
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
   return  4;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 10;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *id = @"Cell";
    OtherTypeViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:id forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    
    cell.img.backgroundColor = [UIColor redColor];
    cell.titleLable.text = @"分类";
    
    return cell;


}


-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(0, 0, 0, 0);//分别为上、左、下、右
}

// 头部高度
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
    return CGSizeMake(ScreenWidth, 40);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
    return CGSizeMake(ScreenWidth, 0);
}
#pragma mark - 头部视图
- (UICollectionReusableView*)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
    if (kind == UICollectionElementKindSectionHeader) {
        UICollectionReusableView *header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"Header" forIndexPath:indexPath];
        header.layer.cornerRadius = 2.0;
        header.layer.masksToBounds = YES;
        header.backgroundColor = BackColor;
        for (UILabel *v in header.subviews) {
            [v removeFromSuperview];
        }
      
        UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, ScreenWidth - 20, 20)];
        lable.text = @"商品";
        lable.font = [UIFont fontWithName:nil size:14];
        lable.textColor = [UIColor blackColor];
        [header addSubview:lable];
        
        return header;
    }
    return nil;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    AddTypeViewController *add = [[AddTypeViewController alloc] init];
    [self.navigationController pushViewController:add animated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
